package com.wutong.teacher_server.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wutong.teacher_server.entity.EduTeacher;
import com.wutong.teacher_server.entity.EduTeacherTest;
import com.wutong.teacher_server.mapper.EduTeacherMapper;
import com.wutong.teacher_server.service.EduTeacherService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 讲师; InnoDB free: 3072 kB 服务实现类
 * </p>
 *
 * @author wutong
 * @since 2020-10-22
 */
@Service
public class EduTeacherServiceImpl extends ServiceImpl<EduTeacherMapper, EduTeacher> implements EduTeacherService {

    @Resource
    EduTeacherMapper eduTeacherMapper;

    @Override
    public Page<EduTeacher> getTeachers(EduTeacher eduTeacher, Page<EduTeacher> page) {

        Page<EduTeacher> teachers = eduTeacherMapper.selectPage(page, null);

        return teachers;
    }

    @Override
    public boolean addTeacher(EduTeacher eduTeacher) {
        int insert = eduTeacherMapper.insert(eduTeacher);
        if (insert > 0) {
            return true ;
        }
        return false;
    }

    @Override
    public boolean updateTeacher(EduTeacher eduTeacher) {
        UpdateWrapper<EduTeacher> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("name",eduTeacher.getName());
        int update = eduTeacherMapper.update(eduTeacher, updateWrapper);
        if(update > 0){
            return true;
        }
        return false;
    }

    @Override
    public List<EduTeacherTest> getList() {

        List<EduTeacherTest> list = eduTeacherMapper.getList();
        return list;
    }
}
